/*
 * Lenovo Group
 * Copyright (c) 2015-2016 All Rights Reserved.
 * 
 * Project Name:itsm-gateway
 * Create Time: 2016年2月6日 下午8:32:02
 */
package com.lenovo.lmrp.server.itsmgateway.test.integration;

import com.lenovo.lmrp.server.itsmgateway.test.unit.RemedySyncServiceTest;
import com.lenovo.lmrp.server.itsmgateway.test.webservice.LenovoAppWsProcessRunServiceImpl;
import com.lenovo.lmrp.server.itsmgateway.test.webservice.LenovoAppWsProcessRunServiceImplService;
import com.lenovo.sdc.framework.util.JSONHelper;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.namespace.QName;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * 
 * @author wujin
 * @version $Id: ItsmSimulator.java, v 0.1 2016年2月3日 上午10:12:30 wujin Exp $
 */
public class ItsmSimulator {
    private static final Logger logger = LoggerFactory.getLogger(RemedySyncServiceTest.class);

    private static final QName SERVICE_NAME = new QName("http://webservice.itsm.lenovoapp.cust/",
        "LenovoAppWsProcessRunServiceImplService");
    private static LenovoAppWsProcessRunServiceImplService ss;
    private static LenovoAppWsProcessRunServiceImpl port;
    
    
    @BeforeClass
    public static void init() throws Exception {
        ss = new LenovoAppWsProcessRunServiceImplService(new URL(
                        "http://te-support.mspcloud.cn:7089/service/LenovoAppInterFace/ItsmProt?wsdl"), SERVICE_NAME);

    }
    
    @Test
    public void testSyncTicket() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd");
        logger.info("Invoking ticketInfo ...");
        StringBuilder sb = new StringBuilder();
        sb.append("<Info>");
        sb.append("<ticketID><![CDATA[EV-10132-210452-39160310-49325]]></ticketID>");
        sb.append("<gettotime><![CDATA[null]]></gettotime>");
        sb.append("<CostAll><![CDATA[100.00]]></CostAll>");
        sb.append("<Summary><![CDATA[mstest13抢单测试，不要动！！！]]></Summary>");
        sb.append("<Expect_WarningTimeRespond><![CDATA[2016-02-16 20:10:10]]></Expect_WarningTimeRespond>");
        sb.append("<Expect_CompleteTimeRespond><![CDATA[2016-02-16 22:10:10]]></Expect_CompleteTimeRespond>");
        sb.append("<Expect_WarningTimeVisit><![CDATA[2016-02-17 10:10:10]]></Expect_WarningTimeVisit>");
        sb.append("<Expect_CompleteTimeVisit><![CDATA[2016-02-17 12:10:10]]></Expect_CompleteTimeVisit>");
        sb.append("<Expect_WarningTimeResolve><![CDATA[2016-02-18 10:10:10]]></Expect_WarningTimeResolve>");
        sb.append("<Expect_CompleteTimeResolve><![CDATA[2016-02-18 20:10:10]]></Expect_CompleteTimeResolve>");
        sb.append("<assigneeGroupID><![CDATA[100004202]]></assigneeGroupID>");
        sb.append("<SupplyCost><![CDATA[null]]></SupplyCost>");
        sb.append("<provinceName><![CDATA[上海市]]></provinceName>");
        sb.append("<assigneeLoginName><![CDATA[mstest19@163.com]]></assigneeLoginName>");
        sb.append("<customerPhone><![CDATA[null]]></customerPhone>");
        sb.append("<ActualCost><![CDATA[null]]></ActualCost>");
        sb.append("<Datetime><![CDATA[null]]></Datetime>");//sb.append("<Datetime><![CDATA[100.00]]></Datetime>");
        sb.append("<reportTime><![CDATA[").append(sdf.format(new Date())).append("]]></reportTime>");
        sb.append("<ChrUserID><![CDATA[null]]></ChrUserID>");
        sb.append("<TicketOprationType><![CDATA[null]]></TicketOprationType>");
        sb.append("<GravenessGrade><![CDATA[0]]></GravenessGrade>");
        sb.append("<SurveyNote><![CDATA[工单同步测试]]></SurveyNote>");
        sb.append("<ProjectID><![CDATA[12000]]></ProjectID>");
        sb.append("<ProjectName><![CDATA[联邦快递（中国）有限公司IT外包-12]]></ProjectName>");
        sb.append("<requestPriority><![CDATA[0]]></requestPriority>");
        sb.append("<ProjectID_Delay><![CDATA[110452]]></ProjectID_Delay>");
        sb.append("<tickettype><![CDATA[0]]></tickettype>");
        sb.append("<DetailProject><![CDATA[联邦快递（中国）有限公司IT外包-12]]></DetailProject>");
        sb.append("<CustomerID><![CDATA[000000000123509]]></CustomerID>");
        sb.append("<AppStatus><![CDATA[null]]></AppStatus>");
        sb.append("<submiterFullname><![CDATA[测试帐号]]></submiterFullname>");
        sb.append("<PendingTime><![CDATA[null]]></PendingTime>");
        sb.append("<CityName><![CDATA[上海市]]></CityName>");
        sb.append("<chrCategory><![CDATA[5%'复印机]]></chrCategory>");
        sb.append("<Solution_Summary><![CDATA[null]]></Solution_Summary>");
        sb.append("<customerMobile><![CDATA[15210511172]]></customerMobile>");
        sb.append("<Attachment_requirements><![CDATA[1]]></Attachment_requirements>");
        sb.append("<ActualCompleteTime><![CDATA[null]]></ActualCompleteTime>");
        sb.append("<assigneeFullName><![CDATA[赵晗]]></assigneeFullName>");
        sb.append("<customerName><![CDATA[jiangren]]></customerName>");
        sb.append("<chrItem><![CDATA[调整、设置]]></chrItem>");
        sb.append("<Description><![CDATA[工单同步测试]]></Description>");
        sb.append("<chrSystem><![CDATA[常规服务]]></chrSystem>");
        sb.append("<TicketInstanceId><![CDATA[HP005056ba565eeXmoVgIPl_KQAO9Y]]></TicketInstanceId>");
        sb.append("<assigneeGroupName><![CDATA[南京APP派单组]]></assigneeGroupName>");
        sb.append("<StepName><![CDATA[服务实施]]></StepName>");
        sb.append("<RespondLevel><![CDATA[5*8*4]]></RespondLevel>");
        sb.append("<BackReasonAPP><![CDATA[null]]></BackReasonAPP>");
        sb.append("<appointment><![CDATA[null]]></appointment>");
        sb.append("<County><![CDATA[null]]></County>");
        sb.append("<chrType><![CDATA[复印机硬件故障]]></chrType>");
        sb.append("<customerAddress><![CDATA[江苏省南京市北京路10号]]></customerAddress>");
        sb.append("<ISGRAB><![CDATA[0]]></ISGRAB>");
        sb.append("<EvaluateResults><![CDATA[null]]></EvaluateResults>");
        sb.append("</Info>");
        try {
            port = ss.getLenovoAppWsProcessRunServiceImplPort();
            String result = port.ticketInfo(sb.toString());
            logger.info("ticketInfo.result=" + result);
            Map<String, Object> jsonObj = JSONHelper.fromJSON(result, Map.class);
            Assert.assertTrue((boolean) jsonObj.get("result"));
            Thread.sleep(3000);
        }
        catch (Exception e) {
            logger.error("Expected exception: Exception has occurred:" + e.getMessage());
        }
    }
    
    
}
